package cate.game.pvp.pointrace.simulator;

import cate.game.framework.SelectedTask;
import cate.game.framework.advanced.AdvancedLongAttributes;
import cate.game.pvp.pointrace.data.PointRaceKV;
import cate.game.pvp.pointrace.timer.PointRaceTimerTask.Settings;

import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;

public abstract class PointRaceSimulator implements SelectedTask<Settings> {

    private final Supplier<PointRaceKV> kvSupplier;

    public PointRaceSimulator(Supplier<PointRaceKV> kvSupplier) {
        this.kvSupplier = Objects.requireNonNull(kvSupplier);
    }

    public abstract void runWith(Settings settings);

    public Consumer<Settings> getSettingsConsumer() {
        return this::runWith;
    }

    protected PointRaceKV getKV() {
        return Objects.requireNonNull(this.kvSupplier.get());
    }

    protected AdvancedLongAttributes getAttributes() {
        return Objects.requireNonNull(getKV().getAttributes());
    }

    @Override
    public void run() {
        // no-op
    }
}
